package com.yic.module.base.dal.mysql.item;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.base.dal.dataobject.item.ItemDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.base.controller.admin.item.vo.*;

/**
 * 产品通用信息 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface ItemMapper extends BaseMapperX<ItemDO> {

    default PageResult<ItemDO> selectPage(ItemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ItemDO>()
                .likeIfPresent(ItemDO::getName, reqVO.getName())
                .likeIfPresent(ItemDO::getCode, reqVO.getCode())
                .eqIfPresent(ItemDO::getDrawCode, reqVO.getDrawCode())
                .eqIfPresent(ItemDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ItemDO::getCategoryId, reqVO.getCategoryId())
                .betweenIfPresent(ItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ItemDO::getId));
    }

    default List<ItemDO> selectList(ItemExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ItemDO>()
                .likeIfPresent(ItemDO::getName, reqVO.getName())
                .likeIfPresent(ItemDO::getCode, reqVO.getCode())
                .eqIfPresent(ItemDO::getDrawCode, reqVO.getDrawCode())
                .eqIfPresent(ItemDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ItemDO::getCategoryId, reqVO.getCategoryId())
                .betweenIfPresent(ItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ItemDO::getId));
    }

    default ItemDO selectByName(String name) {
        return selectOne(new LambdaQueryWrapperX<ItemDO>()
                .eq(ItemDO::getName, name));
    }

    default ItemDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<ItemDO>()
                .eq(ItemDO::getCode, code));
    }

    default List<ItemDO> selectListByCategoryId(Long id) {
        return selectList(new LambdaQueryWrapperX<ItemDO>()
                .eq(ItemDO::getCategoryId, id));
    }

    default ItemDO selectByCategoryId(Long id) {
        return selectOne(new LambdaQueryWrapperX<ItemDO>()
                .eq(ItemDO::getCategoryId, id)
                .last("limit 1"));
    }

    default ItemDO selectByErpId(String erpItemId) {
        return selectOne(new LambdaQueryWrapperX<ItemDO>()
                .eq(ItemDO::getRemark, erpItemId));
    }

    default List<ItemDO> selectListByErpId(Collection<String> erpItemIds) {
        return selectList(new LambdaQueryWrapperX<ItemDO>()
                .inIfPresent(ItemDO::getRemark, erpItemIds));
    }
}
